package com.chat.module.user.service.impl;

import com.comment.exception.ServiceException;
import com.chat.module.user.service.UserLinkInfoService;
import com.comment.pojo.domain.chat.UserLinkInfo;
import io.netty.channel.Channel;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static com.chat.config.web.webSocket.SessionConstant.CHANEL_INFO_KEY;
import static com.chat.config.web.webSocket.handler.WebSocketChannelManager.channelMap;

@Service
public class UserLinkInfoServiceImpl implements UserLinkInfoService {
    @Override
    public List<UserLinkInfo> select(Long userId, Set<Long> userIds) {

        Channel channel = channelMap.get(userId);
        if (channel == null) {
            throw new ServiceException("玩家未登录");
        }

        return userIds.stream().map(playerId -> channelMap.get(playerId).attr(CHANEL_INFO_KEY).get())
                .collect(Collectors.toList());
    }
}
